#!/bin/bash

# JGit使用示例脚本

echo "=== JGit 使用示例 ==="
echo ""

# 创建测试目录
TEST_DIR="test-repo"
if [ -d "$TEST_DIR" ]; then
    echo "清理旧的测试目录..."
    rm -rf "$TEST_DIR"
fi

mkdir "$TEST_DIR"
cd "$TEST_DIR"

echo "1. 初始化仓库..."
java -cp ../target/classes com.jgit.JGit init

echo ""
echo "2. 创建一些测试文件..."
echo "Hello, World!" > hello.txt
echo "This is a test file." > test.txt
mkdir subdir
echo "File in subdirectory" > subdir/file.txt

echo ""
echo "3. 添加文件到暂存区..."
java -cp ../target/classes com.jgit.JGit add hello.txt
java -cp ../target/classes com.jgit.JGit add test.txt
java -cp ../target/classes com.jgit.JGit add subdir/file.txt

echo ""
echo "4. 查看状态..."
java -cp ../target/classes com.jgit.JGit status

echo ""
echo "5. 创建第一个提交..."
java -cp ../target/classes com.jgit.JGit commit -m "Initial commit"

echo ""
echo "6. 查看提交历史..."
java -cp ../target/classes com.jgit.JGit log

echo ""
echo "7. 创建新分支..."
java -cp ../target/classes com.jgit.JGit branch feature

echo ""
echo "8. 查看所有分支..."
java -cp ../target/classes com.jgit.JGit branch

echo ""
echo "9. 切换到新分支..."
java -cp ../target/classes com.jgit.JGit checkout feature

echo ""
echo "10. 修改文件并提交..."
echo "Modified content" >> hello.txt
java -cp ../target/classes com.jgit.JGit add hello.txt
java -cp ../target/classes com.jgit.JGit commit -m "Add modification on feature branch"

echo ""
echo "11. 查看提交历史..."
java -cp ../target/classes com.jgit.JGit log

echo ""
echo "=== 示例完成 ==="
echo "测试仓库位于: $TEST_DIR"

